﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FindArbitrageConsole.Data.Model;


namespace FindArbitrageConsole
{
    public class ArbitrageFindModule
    {
        public List<IEnumerable<KefData>> ByOneMarketWithAllSelections(List<KefData> listKefs)
        {
            var groupped = listKefs.GroupBy(k => k.SelectionId);

            var grouppedSelections = new List<IEnumerable<KefData>>();

            foreach (var grp in groupped)
            {
                grouppedSelections.Add(grp);
            }

            var allAllowCross = CommonFuncs.GetPermutations(grouppedSelections);

            var arbCross = new List<IEnumerable<KefData>>();

            foreach (var variant in allAllowCross)
            {
                if (variant.Select(k=>1/k.KefValue).Sum() < 1)
                    arbCross.Add(variant);
            }

            return arbCross;
        }
        
    }
}
